// ---------------------------------------------------------------------------------------
package {
	
	// FLASH IMPORTS
	import flash.display.Sprite;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	
	// GAME IMPORTS
	import world.World;
	import stats.Stats;
	
	
	[SWF(width = "1024", height = "768", frameRate = '30', backgroundColor = '#FFFFFF')]
		
	// -----------------------------------------------------------------------------------
	public class IsoZSort extends Sprite {
		
		private var _WORLD:World;
		private var _STATS:Stats;
		
		
		// -------------------------------------------------------------------------------
		// CONSTRUCTOR
		// -------------------------------------------------------------------------------
		public function IsoZSort() {

			_WORLD = new World( this );
			
			_WORLD.x = 512;
			_WORLD.y = 50;

			_WORLD.addEventListener( MouseEvent.MOUSE_DOWN,  onStartDrag,  false, 0, true );
			_WORLD.addEventListener( MouseEvent.MOUSE_UP,    onStopDrag,   false, 0, true );
			_WORLD.addEventListener( MouseEvent.MOUSE_WHEEL, onMouseWheel, false, 0, true );
			
			_WORLD.scaleX = _WORLD.scaleY = 0.6;
			
			addChild( _WORLD );
			
			_STATS = new Stats();
			_STATS.y = 720;
			addChild( _STATS );
			
			stage.scaleMode = StageScaleMode.SHOW_ALL;
 		}
		
		// -------------------------------------------------------------------------------
		private function onStartDrag( e:MouseEvent ):void {
			
			_WORLD.startDrag();
		}
		
		// -------------------------------------------------------------------------------
		private function onStopDrag( e:MouseEvent ):void {
			
			_WORLD.stopDrag();
		}
		
		// -------------------------------------------------------------------------------
		private function onMouseWheel( e:MouseEvent ):void {
			
			if      ( (e.delta < 0) && (_WORLD.scaleX > 0.4) ) _WORLD.scaleX = (_WORLD.scaleY -= 0.1);
			else if ( (e.delta > 0) && (_WORLD.scaleX < 1.5) ) _WORLD.scaleX = (_WORLD.scaleY += 0.1);
		}
	}
}